package com.kcnet.qk.controller.pyq;

import android.view.accessibility.AccessibilityEvent;

import com.kcnet.qk.constant.Const;
import com.kcnet.qk.controller.BasePeopleController;
import com.kcnet.qk.util.PreferenceHelper;
import com.kcnet.qk.util.RootShell;

import org.greenrobot.eventbus.EventBus;

import cn.jesse.nativelogger.NLogger;

/**
 * Created by Administrator on 2018/7/9.
 */

public class PyqLlCTR extends BasePeopleController {

    private static String TAG = "朋友圈自动浏览";


    private static PyqLlCTR mRongCloudInstance;

    /**
     * 获取RongCloud 实例。
     *
     * @return RongCloud。
     */
    public static PyqLlCTR getInstance() {
        if (mRongCloudInstance == null) {
            synchronized (PyqLlCTR.class) {

                if (mRongCloudInstance == null) {
                    mRongCloudInstance = new PyqLlCTR();
                }
            }
        }

        return mRongCloudInstance;
    }


    @Override
    public void doTask(AccessibilityEvent event) throws Exception {
        mType = event.getEventType();
        mClassName = (String) event.getClassName();

        if (mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals(Const.WXUI.LauncherUI)) {
            NLogger.d(TAG,"1.进入微信首页 点击 发现 按钮");
            sleepTime(2000);
            tagTextClick("发现");

            sleepTime(1000);
            NLogger.d(TAG,"2.到达发现界面 点击 朋友圈");
            tagTextClick("朋友圈");
        }

        else if (mType == AccessibilityEvent.TYPE_VIEW_SCROLLED && mClassName.equals(Const.LIST_VIEW)
                || mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals(Const.WXUI.SnsTimeLineUI)) {
            NLogger.d(TAG, "3、到达朋友圈主页面 开始滚动列表");
            sleepTimedDefault();
            for(currentAddCount=0;currentAddCount<maxAddCount;currentAddCount++){
                RootShell.swipe(300,800,300,400);
                sleepTimedDefault();
            }
            stopTask();
        }

    }

    /**
     *
     * @param maxAddCount 浏览滑动数量
     * @param minAddTime
     * @param maxAddTime
     */
    public void setParms(int maxAddCount,int minAddTime,int maxAddTime){
        //  stopTask();
        EventBus.getDefault().post(new Boolean(true));
        PreferenceHelper.putBoolean(Const.PREF_KEY_STOP_AUTO_FLAG, true);
        this.maxAddCount = maxAddCount;
        this.minAddTime = minAddTime;
        this.maxAddTime = maxAddTime;
        this.currentAddCount = 0;

    }

}
